<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.username" placeholder="供货名称"></el-input>
				</el-form-item>
				<el-form-item label="商家账号">
					<el-input v-model="filters.phonenum" placeholder="商家账号" clearable ></el-input>
				</el-form-item>
				<el-form-item label="状态">
					<el-select v-model="filters.status" clearable placeholder="请选择状态">
						<el-option value="0" label="全部">全部</el-option>
						<el-option value="1" label="正常">正常</el-option>
						<el-option value="2" label="关闭">关闭</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="findUpUser">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="handleAdd">新增</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="batchHandleOpen" >批量开启</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="batchHandleClose" >批量关闭</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="users" highlight-current-row v-loading="listLoading"  @selection-change="selsChange"  border max-height="620" style="width: 100%;">
			<el-table-column type="selection" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="user.username" width="150px" label="供货名称" show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="shopnum" width="120px" label="商家编号" show-overflow-tooltip>
			</el-table-column>
			<!--<el-table-column prop="user.phonenum" label="商家账号"  >-->
			<!--</el-table-column>-->
			<!--<el-table-column prop="appId" label="渠道APPID">-->
			<!--</el-table-column>-->
			<!--<el-table-column prop="upkey" width="290px" display="none"  label="渠道商密匙">-->
			<!--</el-table-column>-->
			<el-table-column prop="upshopbalance" width="120px" label="商户余额" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="totalMoney" width="120px" label="累计加款" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="repeatNum" width="120px" label="提交次数" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="noticeBalance" width="120px" label="通知金额" show-overflow-tooltip >
			</el-table-column>
<!--			<el-table-column prop="orderCommitAddress" label="订单提交地址" show-overflow-tooltip  >-->
<!--			</el-table-column>-->
			<!--<el-table-column prop="queryBalanceAddress" label="余额查询地址"  >-->
			<!--</el-table-column>-->
<!--			<el-table-column prop="orderStatusAddress" label="订单查询地址"  show-overflow-tooltip >-->
<!--			</el-table-column>-->
			<el-table-column prop="user.userstatus" width="120px"  label="状态"  show-overflow-tooltip>
				<template scope="scope">
				 <span>{{scope.row.user.userstatus == 1 ? '启用' : '禁用' }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="createtime" width="170px"  label="创建时间"  show-overflow-tooltip>
			</el-table-column>

			<el-table-column label="压单" width="100px">
				<template scope="scope">
					<el-switch
							v-model="scope.row.pressOrder"
							@change="changePressOrder(scope.row)"
							active-text=""
							inactive-text="">
					</el-switch>
				</template>
			</el-table-column>
			<el-table-column label="人工" width="100px">
				<template scope="scope">
					<el-switch
							v-model="scope.row.artificial"
							active-text="" @change="changeArtificial(scope.row)"
							inactive-text="">
					</el-switch>
				</template>
			</el-table-column>
			<el-table-column label="查询开关" width="100px" >
				<template scope="scope">
					<el-switch li
							v-model="scope.row.querySwitch"
							active-text="" @change="changeQuerySwitch(scope.row)"
							inactive-text="">
					</el-switch>
				</template>
			</el-table-column>
			<el-table-column label="余额通知" width="100px" >
				<template scope="scope">
					<el-switch li
							   v-model="scope.row.noticeSwitch"
							   active-text="" @change="noticeSwitchSwitch(scope.row)"
							   inactive-text="">
					</el-switch>
				</template>
			</el-table-column>
			<el-table-column prop="user.remark" width="180" label="备注" show-overflow-tooltip  >
			</el-table-column>
			<el-table-column label="操作" width="210" fixed="right">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button size="small" @click="rechargeEdit(scope.$index, scope.row)">充扣值</el-button>
					<el-button size="small" @click="handleEnableShop(scope.$index, scope.row)">{{scope.row.user.userstatus == 2 ? '启用' : '禁用'}}</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>

		<!--编辑界面-->
		<el-dialog title="编辑供货" v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
				<el-form-item label="省份" prop="provinceuuid"  >
					<el-select v-model="editForm.provinceuuid" value-key="provinceuuid"  placeholder="请选择省份" @visible-change="change"   style="width: 325px;">
						<el-option
								v-for="item in options"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="供货商名称" prop="username">
					<el-input v-model="editForm.username" auto-complete="off"></el-input>
				</el-form-item>
				<!--<el-form-item label="商家账号" prop="phonenum">-->
					<!--<el-input v-model="editForm.phonenum"  ></el-input>-->
				<!--</el-form-item>-->
				<el-form-item label="公司名称" >
					<el-input v-model="editForm.wechatid" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="商家编号" prop="shopnum">
					<el-input v-model="editForm.shopnum"  ></el-input>
				</el-form-item>
				<el-form-item label="商家APPID" prop="appId">
					<el-input v-model="editForm.appId"  ></el-input>
				</el-form-item>
				<el-form-item label="商家密匙" prop="upkey">
					<el-input v-model="editForm.upkey"  ></el-input>
				</el-form-item>
				<el-form-item label="重复提交次数" prop="repeatNum">
					<el-input v-model="editForm.repeatNum" placeholder="重复提交次数,0 不重复提交"  ></el-input>
				</el-form-item>
				<el-form-item label="提醒金额">
					<el-input v-model="editForm.noticeBalance"  ></el-input>
				</el-form-item>
				<el-form-item label="订单提交地址" prop="shopnum">
					<el-input v-model="editForm.orderCommitAddress"  ></el-input>
				</el-form-item>
				<el-form-item label="订单查询地址" prop="shopnum">
					<el-input v-model="editForm.orderStatusAddress"  ></el-input>
				</el-form-item>
				<el-form-item label="平台回调地址" prop="shopnum">
					<el-input v-model="editForm.orderCallAddress"  ></el-input>
				</el-form-item>
				<!--<el-form-item label="渠道商ip" prop="upshopip">-->
					<!--<el-input v-model="addForm.upshopip" ></el-input>-->
				<!--</el-form-item>-->
				<el-form-item label="备注">
					<el-input type="textarea" v-model="editForm.remark"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>
		<!--新增界面-->
		<el-dialog title="新增供货" v-model="addFormVisible" :close-on-click-modal="false">
			<el-form :model="addForm" label-width="120px" :rules="addFormRules" ref="addForm">
				<el-form-item label="省份" prop="provinceuuid"  >
					<el-select v-model="addForm.provinceuuid" filterable  :remote-method="remoteMethod"
							   remote placeholder="请选择省份" @change="change" style="width: 335px;">
						<el-option
								v-for="item in options"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="供货商名称" prop="username">
					<el-input v-model="addForm.username" auto-complete="off"></el-input>
				</el-form-item>
				<!--<el-form-item label="商家账号" prop="phonenum">-->
					<!--<el-input v-model="addForm.phonenum"  ></el-input>-->
				<!--</el-form-item>-->
				<el-form-item label="公司名称" >
					<el-input v-model="addForm.wechatid" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="商家编号" prop="shopnum">
					<el-input v-model="addForm.shopnum"  ></el-input>
				</el-form-item>
				<el-form-item label="商家APPID" prop="appId">
					<el-input v-model="addForm.appId"  ></el-input>
				</el-form-item>
				<el-form-item label="商家密匙" prop="upkey">
					<el-input v-model="addForm.upkey"  ></el-input>
				</el-form-item>
				<el-form-item label="重复提交次数" prop="repeatNum">
					<el-input v-model="addForm.repeatNum" placeholder="重复提交次数,0 不重复提交"  ></el-input>
				</el-form-item>
				<el-form-item label="提醒金额">
					<el-input v-model="addForm.noticeBalance"  ></el-input>
				</el-form-item>
				<!--<el-form-item label="余额查询地址" prop="shopnum">-->
					<!--<el-input v-model="addForm.queryBalanceAddress"  ></el-input>-->
				<!--</el-form-item>-->
				<el-form-item label="订单提交地址" prop="shopnum">
					<el-input v-model="addForm.orderCommitAddress"  ></el-input>
				</el-form-item>
				<el-form-item label="订单查询地址" prop="shopnum">
					<el-input v-model="addForm.orderStatusAddress"  ></el-input>
				</el-form-item>
				<el-form-item label="平台回调地址" prop="shopnum">
					<el-input v-model="addForm.orderCallAddress"  ></el-input>
				</el-form-item>
				<!--<el-form-item label="密码" prop="password">-->
					<!--<el-input v-model="addForm.password"  ></el-input>-->
				<!--</el-form-item>-->
				<!--<el-form-item label="渠道商ip" prop="upshopip">-->
					<!--<el-input v-model="addForm.upshopip" ></el-input>-->
				<!--</el-form-item>-->
				<el-form-item label="备注">
					<el-input type="textarea" v-model="addForm.remark"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>
		<!--充值-->
		<el-dialog title="供货商充值"  size="tiny" v-model="rechargeFormVisible" :close-on-click-modal="false" >
			<el-form :model="rechargeForm" label-width="110px" ref="rechargeForm"  >

				<el-form-item label="剩余金额" prop="upshopbalance" >
					<el-input v-model="rechargeForm.upshopbalance"   :disabled="true" ></el-input>
				</el-form-item>

				<el-form-item label="充扣值选项">
					<el-radio-group v-model="rechargeForm.recharge">
						<el-radio  :label="1">充值</el-radio>
						<el-radio  :label="0">扣款</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="充值金额" prop="rechargeamount" :rules="[
				  { required: true, message: '不能为空'},
				  { type: 'number', message: '金额必须为数字值'}
				]">
					<el-input type="rechargeamount" v-model.number="rechargeForm.rechargeamount" auto-complete="off" @change="rechargeamountchange"  ></el-input>
				</el-form-item>
				<el-form-item label="总金额" prop="sumamount">
					<el-input type="text" v-model="rechargeForm.sumamount"  ></el-input>
				</el-form-item>
				<el-form-item label="备注">
					<el-input type="textarea" v-model="rechargeForm.remark"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="rechargeFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="rechargeSubmit" :loading="rechargeLoading">提交</el-button>
			</div>
		</el-dialog>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	import { addUpUser,findUpUser,findAllPro,findOneShopInfo ,updateUpShopInfo,upRechargeRecord,
		updateArtificial,updatePressOrder,changeQuerySwitch , handleEnableShop,noticeUpSwitch} from '../../api/api';
    var crypto = require('crypto');
	export default {
        data() {
            return {
                filters: {
                    username: '',
                    phonenum:'',
					status:''
                },
                options :[],
                users: [],
				sels:[],
                total: 0,
                start:0,
                pageSize:10,
                listLoading: false,
				isShow : false,
                editFormVisible: false,//编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    username: [
                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ]
//                    , phonenum: [
//                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ]
//                    , password: [
//                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ]
//                    , upshopip: [
//                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ]
                    ,shopnum: [
                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ], provinceuuid: [
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ]
//					, orderCommitAddress: [
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ], queryBalanceAddress: [
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ], orderStatusAddress: [
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ]
                },
                //编辑界面数据
                editForm: {
                    username: '',
                    phonenum: '',
                    provinceuuid: '',
                    shopnum: '',
                    remark: '',
                    useruuid:'',
                    orderCommitAddress:'',
                    queryBalanceAddress:'',
                    orderStatusAddress:'',
					orderCallAddress:'',
                    upkey:'',
                    appId:'',
					repeatNum:0,
					wechatid:'',
					noticeBalance:0
                },

                addFormVisible: false,//新增界面是否显示
                addLoading: false,
                addFormRules: {
                    username: [
                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ]
//                    , phonenum: [
//                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ]
//                    , password: [
//                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ]
//                    , upshopip: [
//                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
//                        {required: true, message: '不能为空', trigger: 'blur'}
//                    ]
					,shopnum: [
                        {min: 1, max: 30, message: '长度在 1 到 20 个字符', trigger: 'blur'},
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ], provinceuuid: [
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ]

                },
                rechargeForm:{
                    upshopbalance:'',
                    rechargeamount:0,
                    sumamount:'',
                    upshopuuid:'',
                    remark:'',
                    recharge:1
				},
                rechargeFormVisible : false,
                rechargeLoading : false,
//                rechargeRules:{
//                    rechargeamount: [
//						{required: true, message: '不能为空', trigger: 'blur'},
//                        {type:'number', message: '必须为纯数字', trigger: 'blur'},
//                        {min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur'}
//                	]
//				},
                //新增界面数据
                addForm: {
                    username: '',
                    phonenum: '',
                    password: '',
                    usertype: '4',
                    upshopip: '',
                    provinceuuid: '',
                    shopnum: '',
                    remark: '',
                    upkey:'',
                    orderCommitAddress:'',
                    queryBalanceAddress:'',
					orderCallAddress:'',
                    orderStatusAddress:'',
                    appId:'',
					repeatNum:'',
					wechatid:'',
					noticeBalance:0
                }

            }
        },
        methods: {
            findUpUser() {
                let para = {
                    start: this.start,
                    pageSize:this.pageSize,
                    shopName: this.filters.username,
                    phonenum:this.filters.phonenum,
					userstatus: this.filters.status == 0 ? "" : this.filters.status
                };
                this.listLoading = true;
                findUpUser(para).then((datas) => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.users = data.result;
                        this.total = data.totalCount;
                    }
                    this.listLoading = false;
                });
            },
            rechargeEdit:function(index, row){
				this.rechargeFormVisible = true;
				this.rechargeForm.upshopbalance = row.upshopbalance;
                this.rechargeForm.upshopuuid = row.upshopuuid;
			},
            rechargeamountchange : function(){
                try{
                    var reg = new RegExp("^([0-9]|[.][0-9])*$");
                    if(reg.test(this.rechargeForm.rechargeamount) ){
                        if(this.rechargeForm.recharge == 1){
                            this.rechargeForm.sumamount = numAdd (this.rechargeForm.upshopbalance,this.rechargeForm.rechargeamount);
                        }else{
                            this.rechargeForm.sumamount = numSubtraction (this.rechargeForm.upshopbalance,this.rechargeForm.rechargeamount);
                        }
					}else{
                        this.rechargeForm.rechargeamount = "";
					}
				}catch (e){
                    console.log(e);
				}
			},
			handleEnableShop(index, row){
				this.$confirm('确认禁用或启用?', '提示', {
					type: 'warning'
				}).then(() => {
					let param = {
						useruuid : row.user.useruuid,
						userstatus : row.user.userstatus == 1 ? 2 : 1
					}
					handleEnableShop(param).then( res =>{
						let { message, code, data } = res;
						if (code !== "0") {
							this.$message({
								message: message,
								type: 'error'
							});
						};
						this.findUpUser();
					});
				}).catch(() => {
				});
			},
            //充值
            rechargeSubmit: function () {
                this.$refs.rechargeForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.rechargeLoading = true;
                            let para = {
                                remark :this.rechargeForm.remark,
                                upshopuuid:this.rechargeForm.upshopuuid,
                                upshopbalance : this.rechargeForm.rechargeamount,
                                recharge:this.rechargeForm.recharge
                            };
                            upRechargeRecord(para).then((datas) => {
                                this.rechargeLoading = false;
                                let { message, code, data } = datas;
                                if (code !== "0") {
                                    this.$message({
                                        message: message,
                                        type: 'error'
                                    });
                                }
                                this.$refs['rechargeForm'].resetFields();
                                this.rechargeFormVisible = false;
                                this.findUpUser();
                            });
                        });
                    }
                });
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                //查询省份
                let para = {
                    page: ''
                };
                findAllPro(para).then(datas => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.options = data;
                        let para = {
                            upshopuuid:row.upshopuuid
                        };
                        findOneShopInfo(para).then( datas =>{
                            let { message, code, data } = datas;
                            if (code !== "0") {
                                this.$message({
                                    message: message,
                                    type: 'error'
                                });
                            } else {
//                                this.editForm = Object.assign({},data);
								this.editForm.upshopuuid =  data.upshopuuid;
                                this.editForm.username = data.user.username;
                                this.editForm.phonenum = data.user.phonenum;
                                this.editForm.remark = data.user.remark;
                                this.editForm.shopnum = data.shopnum;
                                this.editForm.provinceuuid = data.provincialInformation.provinceuuid;
                                this.editForm.useruuid = data.user.useruuid;
                                this.editFormVisible = true;
                                this.editForm.orderCommitAddress= data.orderCommitAddress ;
								this.editForm.queryBalanceAddress = data.queryBalanceAddress;
                                this.editForm.orderStatusAddress = data.orderStatusAddress;
								this.editForm.orderCallAddress = data.orderCallAddress;
                                this.editForm.upkey = data.upkey;
								this.editForm.appId = data.appId;
								this.editForm.repeatNum = data.repeatNum;
								this.editForm.wechatid = data.user.wechatid;
								this.editForm.noticeBalance = data.noticeBalance;
                            }
                        });
                    }
                });
            },
            change:function(option){
				if(!option){
				    let temp =  this.editForm.provinceuuid;
                    this.editForm.provinceuuid = "";
                    this.editForm.provinceuuid = temp;
                }
			},
            //显示新增界面
            handleAdd: function () {
                this.addFormVisible = true;
                //查询省份
                let para = {
                    page: ''
                };
                findAllPro(para).then(datas => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.options = data;
                    }
				});
                this.addForm = {
                    username: '',
                    phonenum: '',
                    password: '',
                    usertype: '4',
                    upshopip: '',
                    provinceuuid: '',
                    shopnum: '',
                    remark: '',
                    upkey:'',
                    options :this.options,
					orderCallAddress:'',
                    appId : '',
					repeatNum:0,
					wechatid:'',
					noticeBalance:0
                };
            },
            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.editLoading = true;
                            //NProgress.start();
                            let para = {
                                useruuid : this.editForm.useruuid,
                                phonenum: this.editForm.phonenum,
                                remark: this.editForm.remark,
                                upshopip:'',
                                appId : this.editForm.appId,
                                upkey:this.editForm.upkey,
                                provinceuuid: this.editForm.provinceuuid,
                                shopnum: this.editForm.shopnum,
                                upshopuuid:this.editForm.upshopuuid,
                                username:this.editForm.username,
								orderCallAddress:this.editForm.orderCallAddress,
                                orderCommitAddress:this.editForm.orderCommitAddress,
                                queryBalanceAddress:this.editForm.queryBalanceAddress,
								orderStatusAddress:this.editForm.orderStatusAddress,
								repeatNum: this.editForm.repeatNum,
								wechatid: this.editForm.wechatid,
								noticeBalance:this.editForm.noticeBalance
							};

                            updateUpShopInfo(para).then((datas) => {
                                this.editLoading = false;
                                let { message, code, data } = datas;
                                if (code !== "0") {
                                    this.$message({
                                        message: message,
                                        type: 'error'
                                    });
                                }
                                this.$refs['editForm'].resetFields();
                                this.editFormVisible = false;
                                this.findUpUser();
                            });
                        });
                    }
                });
            },
            //新增
            addSubmit: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.addLoading = true;
                            let para = Object.assign({}, this.addForm);
							para.queryBalanceAddress ='';
                            var md5 = crypto.createHash('md5');
                            para.password = md5.update(para.password).digest('hex');
                            addUpUser(para).then((datas) => {
                                this.addLoading = false;
                                let { message, code, data } = datas;
                                if (code !== "0") {
                                    this.$message({
                                        message: message,
                                        type: 'error'
                                    });
                                }

                                this.$refs['addForm'].resetFields();
                                this.addFormVisible = false;
                                this.findUpUser();
                            });
                        });
                    }
                });
            },handleCurrentChange:function(val){
                this.start = val - 1;
                this.findUpUser();
            },
            handleSizeChange:function(val){
                this.pageSize = val;
                this.findUpUser();
            },
            remoteMethod(query) {
                if (query !== '') {
//                    this.loading = true;
//                    setTimeout(() => {
//                        this.loading = false;
//                        this.options4 = this.list.filter(item => {
//                            return item.label.toLowerCase()
//                                    .indexOf(query.toLowerCase()) > -1;
//                        });
//                    }, 200);
                } else {
//                    this.options4 = [];
                }
            },
			changePressOrder(row){

				updatePressOrder(row).then((datas) => {
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}
					this.findUpUser();
				});
			},
			changeArtificial(row){
				updateArtificial(row).then((datas) => {
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}
					this.findUpUser();
				});
			},
			changeQuerySwitch(row){
				changeQuerySwitch(row).then((datas) => {
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}
					this.findUpUser();
				});
			},
			noticeSwitchSwitch(row){
				noticeUpSwitch(row).then((datas) => {
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}
					this.findUpUser();
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			batchHandleOpen(){
				this.batachShops("open");
			},
			batchHandleClose(){
				this.batachShops("close");
			},
			batachShops(type){
				if(this.sels.length == 0){
					this.$message({
						message: "请选择渠道",
						type: 'error'
					});
					return;
				}
				this.$confirm('确认批量关闭or启用该商家状态吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					for(var i = 0 ; i < this.sels.length ; i++){
						let param = {
							useruuid : this.sels[i].user.useruuid,
							userstatus : type == "close"  ? 2 : 1
						}
						handleEnableShop(param).then( res =>{

						});
					}
					this.$message({
						message: '操作成功',
						type: 'success'
					});
					this.listLoading = false;
					this.findUpUser();
				}).catch((e) => {
					console.log(e)
				});
			}
        },
		mounted(){
            this.findUpUser();
        }
    }
     function  numAdd(num1, num2) {
        var baseNum, baseNum1, baseNum2;
        try {
            baseNum1 = num1.toString().split(".")[1].length;
        } catch (e) {
            baseNum1 = 0;
        }
        try {
            baseNum2 = num2.toString().split(".")[1].length;
        } catch (e) {
            baseNum2 = 0;
        }
        baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
        return (num1 * baseNum + num2 * baseNum) / baseNum;
    }

    function  numSubtraction(num1, num2) {
        var baseNum, baseNum1, baseNum2;
        try {
            baseNum1 = num1.toString().split(".")[1].length;
        } catch (e) {
            baseNum1 = 0;
        }
        try {
            baseNum2 = num2.toString().split(".")[1].length;
        } catch (e) {
            baseNum2 = 0;
        }
        baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
        return (num1 * baseNum - num2 * baseNum) / baseNum;
    }
</script>
<style scoped>

</style>
